--
-- Author: shunguo.chen
-- Date: 2017-11-27 11:42:45
--
-- MountActiveRender 激活的坐骑

local MountRender = import(".MountRender")

local ClassRef = app.mvc.createRenderClass(...)

--data = Mount
function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.MountActiveNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end       
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end 

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())
	
	self._render = MountRender.create(self._ui.icon)
    self._render:setClickEnable(false)
    self._selectNode = self._ui["Panel/mount_effect_1_1"]

	display.uiAddClick(self._ui.Panel, function(sender, eventType)
	    if self._data and not self:isSelected() then
            self:setSelected(not self:isSelected())
            executeFunc(self._onClick, self)
        end
	end)

	self:refresh()
end

function ClassRef:refresh()
    self:setVisible(self._data ~= nil)
    if self._data then
        self._render:setData(self._data)
        self._render:hideStarPanel()
        local star = self._data:getStar()
        self._ui.star:loadTexture(string.format(Res.MountStarPath, star))
    else
        self._render:setData()
    end
end

function ClassRef:isSelected()
    return self._selectNode:isVisible()
end
function ClassRef:setSelected(b)
    self._selectNode:setVisible(b)
end

function ClassRef:setClickEnable(b)
	self._ui.Panel:setTouchEnabled(b)
end

function ClassRef:setClickHandler(cb)
    self._onClick = cb
end

function ClassRef:setBtnClick(cb)
	self._onClick = cb
end

function ClassRef:setLock(trueOrFalse)
end

return ClassRef